package com.test.spring.controller;

import com.test.spring.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/B")
public class BeanController {
    @Autowired
    private ApplicationContext context;

    @Autowired
    private Dog singletonDog;

    @RequestMapping("/single")
    public void single() {
        // 从context获取Bean
        Dog contextDog = context.getBean("singletonDog",Dog.class);
        System.out.println(contextDog);
        // 打印注入进来的Dog类的Bean
        System.out.println(singletonDog);
    }

    @Autowired
    private Dog prototypeDog;
    @RequestMapping("/prototype")
    public void prototype() {
        // 从context获取Bean
        Dog contextDog = context.getBean("prototypeDog",Dog.class);
        System.out.println(contextDog);
        // 打印注入进来的Dog类的Bean
        System.out.println(prototypeDog);
    }
}
